home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / dec / qdss / qdfill.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-27  |  8.3 KB  |  277 lines

  1. /***********************************************************
  2. Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. #include "X.h"
  26.  
  27. #include "misc.h"
  28. #include "windowstr.h"
  29. #include "gcstruct.h"
  30. #include "qd.h"
  31. #include "qdgc.h"
  32. #include "qdprocs.h"
  33. #include "pixmapstr.h"
  34.  
  35. /* Mixing of levels! Needed for ScreenHeight */
  36. #include "libtl/tl.h"
  37.  
  38. /*
  39.  * make this FillSpans instead?        XX
  40.  */
  41. void
  42. qdPolyFillBoxesOddSize(pWin, pGC, nrect, pdestboxes)
  43.     WindowPtr    pWin;
  44.     GCPtr    pGC;
  45.     int        nrect;           /* number of rectangles to fill */
  46.     BoxPtr    pdestboxes;
  47. {
  48.     int        nr, ok;
  49.     register BoxPtr pbox;
  50.     RegionPtr    pSaveGCclip = QDGC_COMPOSITE_CLIP(pGC);
  51.     RegionPtr    pcompregion;        /* built from pboxes argument */
  52.     int rx, ry;  /* origin in window coordinates */
  53.     int width, height;
  54.     int ix, iy;    /* steps through the box; in window coordinate */
  55.     PixmapPtr    pTile =
  56. #ifdef X11R4
  57.     pGC->fillStyle == FillTiled ? pGC->tile.pixmap : pGC->stipple;
  58. #else
  59.     pGC->fillStyle == FillTiled ? pGC->tile : pGC->stipple;
  60. #endif
  61.     int xStart;
  62.  
  63.     pcompregion = qdRegionInit( pdestboxes, nrect);
  64.     miTranslateRegion( pcompregion, pGC->lastWinOrg.x, pGC->lastWinOrg.y);
  65.     miIntersect( pcompregion, pcompregion, QDGC_COMPOSITE_CLIP(pGC));
  66.     QDGC_COMPOSITE_CLIP(pGC) = pcompregion;
  67.  
  68.     rx = pcompregion->extents.x1 - pGC->lastWinOrg.x;
  69.     ry = pcompregion->extents.y1 - pGC->lastWinOrg.y;
  70.     width = pcompregion->extents.x2 - pcompregion->extents.x1;
  71.     height = pcompregion->extents.y2 - pcompregion->extents.y1;
  72.     xStart = rx - UMOD( rx-pGC->patOrg.x, QDPIX_WIDTH(pTile));
  73.     iy = ry - UMOD( ry-pGC->patOrg.y, QDPIX_HEIGHT(pTile));
  74.     /*
  75.      * for each row of tiles, bump iy
  76.      * subtract enough off of initial iy to align tile
  77.      *
  78.      * for each column of tiles, bump ix
  79.      * subtract enough off of initial ix to align tile
  80.      */
  81.  
  82.     switch ( pGC->fillStyle) {
  83.       case FillStippled: {
  84.       long gcval;
  85.       gcval = (long)FillSolid;
  86.       /*  temporarily set fillstyle to FillSolid */
  87.       DoChangeGC(pGC, GCFillStyle, &gcval, 0);
  88.       ValidateGC(pWin, pGC);
  89.       for ( ; iy < ry + height; iy += QDPIX_HEIGHT(pTile))
  90.           for (ix = xStart; ix < rx + width; ix += QDPIX_WIDTH(pTile))
  91.           qdPushPixels(pGC, pTile, pWin,
  92.                    QDPIX_WIDTH(pTile), QDPIX_HEIGHT(pTile),
  93.                    ix, iy);
  94.       gcval = (long)FillStippled;
  95.       DoChangeGC(pGC, GCFillStyle, &gcval, 0);
  96.       ValidateGC(pWin, pGC);
  97.       break;
  98.       }
  99.       case FillOpaqueStippled:
  100.     for ( ; iy < ry + height; iy += QDPIX_HEIGHT(pTile))
  101.         for (ix = xStart; ix < rx + width; ix += QDPIX_WIDTH(pTile))
  102. #ifdef X11R4
  103.         (*pGC->ops->CopyPlane)(pTile, pWin, pGC, 0, 0,
  104. #else
  105.         (*pGC->CopyPlane)(pTile, pWin, pGC, 0, 0,
  106. #endif
  107.                   QDPIX_WIDTH(pTile), QDPIX_HEIGHT(pTile),
  108.                   ix, iy, 1);
  109.     break;
  110.       case FillTiled: {
  111. #if 1
  112. #define TILE_X 0
  113. #define TILE_Y ScreenHeight
  114.       if ( tlConfirmPixmap(pTile)
  115.           && (pWin->drawable.type == DRAWABLE_WINDOW
  116.           || QDPIX_Y((QDPixPtr)pWin) != NOTOFFSCREEN)) {
  117.           int tileX, tileY;
  118.           int tileW = QDPIX_WIDTH(pTile);
  119.           int tileH = QDPIX_HEIGHT(pTile);
  120.           if (tileW < 32 && tileH < 32) {
  121.           tileW = (32 / tileW) * tileW;
  122.           tileH = (32 / tileH) * tileH;
  123.           tileX = TILE_X;
  124.           tileY = TILE_Y;
  125.           /* Makes gross assumptions about what tlrotile does! */
  126.           tlrotile(pTile, pGC->patOrg, NULL);
  127.           } else {
  128.           tileX = QDPIX_X((QDPixPtr)pTile);
  129.           tileY = QDPIX_Y((QDPixPtr)pTile);
  130.           }
  131.           for ( ; iy < ry + height; iy += tileH)
  132.           for (ix = xStart; ix < rx + width; ix += tileW)
  133.               tlbitblt(pGC,
  134.                    pGC->lastWinOrg.x + ix, pGC->lastWinOrg.y + iy,
  135.                    tileW, tileH, tileX, tileY);
  136.           }
  137.       else
  138. #endif
  139.           for ( ; iy < ry + height; iy += QDPIX_HEIGHT(pTile))
  140.           for (ix = xStart; ix < rx + width; ix += QDPIX_WIDTH(pTile))
  141. #ifdef X11R4
  142.               (*pGC->ops->CopyArea)(pTile, pWin, pGC, 0, 0,
  143. #else
  144.               (*pGC->CopyArea)(pTile, pWin, pGC, 0, 0,
  145. #endif
  146.                        QDPIX_WIDTH(pTile), QDPIX_HEIGHT(pTile),
  147.                        ix, iy);
  148.       break;
  149.       }
  150.       case FillSolid:
  151.     FatalError( "Should have called tldrawshapes code!\n");
  152.     break;
  153.     }
  154.     miRegionDestroy( pcompregion);
  155.     QDGC_COMPOSITE_CLIP(pGC) = pSaveGCclip;
  156. }
  157.  
  158. void
  159. qdPolyFillRectOddSize( pDrawable, pGC, nrect, prect)
  160.     DrawablePtr    pDrawable;
  161.     GCPtr    pGC;
  162.     int        nrect;           /* number of rectangles to fill */
  163.     xRectangle * prect;          /* Pointer to first rectangle to fill */
  164. {
  165.     BoxPtr    pdestboxes;
  166.     register BoxPtr    pdb;
  167.     int        nr;
  168.  
  169.     if ( nrect == 0) return;
  170.  
  171.     pdb = pdestboxes = (BoxPtr) ALLOCATE_LOCAL( nrect*sizeof(BoxRec));
  172.     /*
  173.     * turn the rectangles into Boxes
  174.     */
  175.     for (nr = nrect; --nr >= 0; pdb++, prect++)
  176.     {
  177.     pdb->x1 = prect->x;
  178.     pdb->x2 = prect->x + (int)prect->width;
  179.     pdb->y1 = prect->y;
  180.     pdb->y2 = prect->y + (int)prect->height;
  181.     }
  182.  
  183.     qdPolyFillBoxesOddSize((WindowPtr)pDrawable, pGC, nrect, pdestboxes);
  184.     DEALLOCATE_LOCAL(pdestboxes);
  185. }
  186.  
  187. void
  188. qdFillPolygon( pDrawable, pGC, shape, mode, npt, pptInit)
  189.     DrawablePtr         pDrawable;
  190.     register GCPtr      pGC;
  191.     int                 shape, mode;
  192.     register int        npt;
  193.     DDXPointPtr         pptInit;
  194. {
  195.     DDXPointPtr         abspts;
  196.     DDXPointPtr         closepts;
  197.     Bool        allocated = FALSE;
  198.  
  199.     if ( pDrawable->type != DRAWABLE_WINDOW || shape != Convex ||
  200.         pGC->fillStyle != FillSolid)
  201.     {
  202.     miFillPolygon( pDrawable, pGC, shape, mode, npt, pptInit);
  203.     return;
  204.     }
  205.  
  206.     if ( npt == 0)        /* make sure abspts[0] is valid */
  207.      return;
  208.     if ( mode == CoordModeOrigin)
  209.     abspts = pptInit;
  210.     else    /* CoordModePrevious */
  211.     {
  212.     register int    ip;
  213.  
  214.     /* It is 'npt=1' in case we need to close the polygon below */
  215.     abspts = (DDXPointPtr) ALLOCATE_LOCAL( (npt+1) * sizeof( DDXPointRec));
  216.         allocated = TRUE;
  217.     abspts[ 0].x = pptInit[ 0].x;
  218.     abspts[ 0].y = pptInit[ 0].y;
  219.     for ( ip=1; ip<npt; ip++)
  220.     {
  221.         abspts[ ip].x = abspts[ ip-1].x + pptInit[ ip].x;
  222.         abspts[ ip].y = abspts[ ip-1].y + pptInit[ ip].y;
  223.     }
  224.  
  225.     }
  226.     /* close the polygon if necessary */
  227.     if (abspts[npt-1].x != abspts[0].x
  228.         || abspts[npt-1].y != abspts[0].y)    /* not closed */
  229.     {
  230.     register int    ip;
  231.  
  232.     if (allocated)
  233.         closepts = abspts;
  234.     else {
  235.         allocated = TRUE;
  236.         closepts =
  237.         (DDXPointPtr) ALLOCATE_LOCAL( (npt+1) * sizeof(DDXPointRec));
  238.         for ( ip = npt; --ip >= 0; ) {
  239.         closepts[ ip].x = abspts[ ip].x;
  240.         closepts[ ip].y = abspts[ ip].y;
  241.         }
  242.     }
  243.     closepts[npt].x = abspts[0].x;
  244.     closepts[npt].y = abspts[0].y;
  245.     npt++;    /* add duplicate point to end */
  246.     }
  247.     else
  248.     closepts = abspts;
  249.     tlconpoly( (WindowPtr)pDrawable, pGC, npt, closepts);
  250.     if (allocated) DEALLOCATE_LOCAL( closepts );
  251. }
  252.  
  253. void
  254. qdPixFillRect(pPix, pGC, nshapes, pshape)
  255.      QDPixPtr pPix;
  256.      GCPtr pGC;
  257.      int nshapes;
  258.      DDXPointPtr pshape;
  259.      
  260. {
  261.     extern int PixmapUseOffscreen;
  262. /* if PixmapUseOffscreen allow debugging of tlSolidSpans */
  263.     if (QD_PIX_DATA(&pPix->pixmap) == NULL) {
  264.     extern void tlSolidRects(), tlTiledRects(),
  265.         tlStipRects(), tlOpStipRects();
  266.     static void (*FillFuncs[4])() = {
  267.         tlSolidRects, tlTiledRects, tlStipRects, tlOpStipRects};
  268.     /* make dummy window and use that as the drawable */
  269.     SETUP_PIXMAP_AS_WINDOW(&pPix->pixmap.drawable, pGC);
  270.     CHECK_MOVED(pGC, &pPix->pixmap.drawable);
  271.     (*FillFuncs[pGC->fillStyle])(pPix, pGC, nshapes, pshape);
  272.     CLEANUP_PIXMAP_AS_WINDOW(pGC);
  273.     }
  274.     else
  275.     miPolyFillRect(pPix, pGC, nshapes, pshape);
  276. }
  277.